<template>
  <span>
    <TreeTable
      :treeInfo="treeInfo"
      :dataSource="records"
      :columns="columns"
      @row-click="onRowClick"
    />

    <template v-if="!readonly">
      <a-button size="small" @click="onCreate"> 添加 </a-button>
    </template>
  </span>
</template>

<script setup>
import TreeTable from './TreeTable.vue'

import { useSubTree } from './subTreeApi.js'

const props = defineProps(['readonly', 'records', 'node', 'parentInfo'])
const emit = defineEmits(['row-click', 'row-new'])

const { treeInfo, columns } = useSubTree(props)

function onRowClick(record) {
  console.log(record)
  emit('row-click', record)
}

function onCreate() {
  emit('row-new')
}
</script>

<style scoped></style>
